<?php

class User extends Controller{

	function User(){
		parent::Controller();
		$this->load->library('validation');
		$this->load->helper('url');
		$this->load->library('session');
		$this->load->library('validation');
		$this->load->database();

		//$this->load->view('user_register');
	}
	function index(){
		$this->load->view('html/login');
	}
	function login(){
		$rules['username'] = "required";
		$rules['password'] = "required";
		$this->validation->set_rules($rules);

		if ($this->validation->run() == FALSE){
			$this->load->view('html/login');
		}
		else
		{
			$this->load->model('checkmodel');
			$user_data = $this->checkmodel->check($_POST['username'],$_POST['password']);
			if($user_data[0]->userid){
				//$data=$this->session;
				@$userdata=array(
				@'username'=>$_POST[username],
				);
				@$this->session->set_userdata($userdata);
				//print_r($this->session->userdata);
				$refer=$_SERVER['HTTP_REFERER'];
				//echo anchor($refer,'������һҳ');
				/*echo "<script>alert('dddd');history.back();</script>";*/
				//echo ""
				//echo $this->session->userdata['username'];

				redirect('/user/userindex','refresh');

			}
			else{
				echo "the wrong password.";
				redirect('/user/login','refresh');
			}
			//print_r($user_data);

		}

	}
	function	userindex(){
		//echo $this->session->userdata['username'];
		$this->load->model('cartmodel');
		$username=$this->session->userdata('username');
		$data['query']=$this->cartmodel->select_cart($username);
		//$a=$query->result();
		//print_r($a);exit;
		$this->load->view('html/userindex',$data);
	}
	function regindex(){
		$this->load->view('html/register');
	}
	function regisger(){
		$this->load->view('html/register');
	}
	function  reg(){
		$rules['username'] = "required";
		$rules['password'] = "required|md5";
		$rules['email'] = "required|valid_email";
		$rules['truename']="required";
		$reg_time=time()+28800;
		//echo $reg_time;
		//print_r($_POST);
		$_POST['reg_time']=$reg_time;
		//print_r($_POST);exit;
		echo  date('Y-m-d H:i:s',$reg_time);
		$this->validation->set_rules($rules);
		if($this->validation->run() == FALSE){
			$this->load->view('user_register');

		}
		else{
			$this->load->model('regmodel');
			$this->regmodel->reg($_POST);

		}

	}
	
	function logoff(){
		$this->session->sess_destroy();
		redirect('/display_index/index','refresh');
	}





}

?>